package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;

import controllers.ClientController;
import javax.swing.ImageIcon;

import entity.UserLoginInfo;

public class UpdatePricesUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	public static ArrayList<String> list= new ArrayList<String>();
	ClientController clientCont;
	String s1,s2,s3,s4,s5;

	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UpdatePricesUI frame = new UpdatePricesUI(list);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the Update PricesUI frame.
	 */
	public UpdatePricesUI(ArrayList<String> names) {
		UpdatePricesUI.list=names;
		String[] name=new String[list.size()];
		name=(String[]) names.toArray(new String[names.size()]);
		this.s1=name[0];
		this.s2=name[1];
		this.s3=name[2];
		this.s4=name[3];
		this.s5=name[4];
		
		if(s1.equals("0")) { s1="No change";}
		if(s2.equals("0")) { s2="No change";}
		if(s3.equals("0")) { s3="No change";}
		if(s4.equals("0")) { s4="No change";}
		if(s5.equals("0")) { s5="No change";}
								
		
		setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\casper\\Desktop\\\u05DE\u05DB\u05D1\u05D9.jpg"));
		setTitle("update prices window");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 629, 365);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblWelcomeToUpdate = new JLabel("welcome to update prices window");
		lblWelcomeToUpdate.setBounds(271, 5, 210, 21);
		lblWelcomeToUpdate.setFont(new Font("Tekton Pro Cond", Font.ITALIC, 15));
		
		JLabel lblService = new JLabel("SERVICE");
		lblService.setBounds(78, 37, 53, 16);
		lblService.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
		
		JLabel lblPrice = new JLabel("PRICE");
		lblPrice.setBounds(292, 37, 37, 16);
		lblPrice.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
		
		JLabel lblPurchaseSample = new JLabel("purchase sample");
		lblPurchaseSample.setBounds(63, 64, 120, 14);
		
		JLabel lblPurchasePicture = new JLabel("purchase picture");
		lblPurchasePicture.setBounds(63, 89, 120, 14);
		
		JLabel lblPurchaseLayer = new JLabel("purchase layer");
		lblPurchaseLayer.setBounds(63, 114, 101, 14);
		
		JLabel lblTimaLocationMember = new JLabel("time location member");
		lblTimaLocationMember.setBounds(63, 139, 132, 14);
		
		JLabel lblPackageMember = new JLabel("package member");
		lblPackageMember.setBounds(63, 164, 120, 14);
		
		JLabel lblNewLabel = new JLabel(s1);
		lblNewLabel.setBounds(292, 64, 55, 14);
		
		JLabel lblPicturettt = new JLabel(s2);
		lblPicturettt.setBounds(292, 89, 55, 14);
		
		JLabel lblLayerttt = new JLabel(s3);
		lblLayerttt.setBounds(292, 114, 55, 14);
		
		JLabel lblTimettt = new JLabel(s4);
		lblTimettt.setBounds(292, 139, 55, 14);
		
		JLabel lblPacttt = new JLabel(s5);
		lblPacttt.setBounds(292, 164, 55, 14);
		
		JButton btnConfirm = new JButton("confirm");
		btnConfirm.setBounds(23, 208, 141, 23);
		btnConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try{
				btnConfirmActionPerformed(e);
				}catch(Exception e1){
					e1.printStackTrace();
				}
				
				dispose();
			}
		});
		
		
		
		
		JButton btnBack = new JButton("back");
		btnBack.setBounds(174, 208, 120, 23);
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				WorkerGUI frame = new WorkerGUI();
				frame.setVisible(true);
				dispose();
			}
		});
		
		
		JButton btnCancel = new JButton("cancel");
		btnCancel.setBounds(304, 208, 126, 23);
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		contentPane.setLayout(null);
		contentPane.add(lblWelcomeToUpdate);
		contentPane.add(lblPurchasePicture);
		contentPane.add(lblPurchaseSample);
		contentPane.add(lblPurchaseLayer);
		contentPane.add(lblPackageMember);
		contentPane.add(btnConfirm);
		contentPane.add(lblTimaLocationMember);
		contentPane.add(lblService);
		contentPane.add(lblPrice);
		contentPane.add(lblNewLabel);
		contentPane.add(lblPicturettt);
		contentPane.add(lblLayerttt);
		contentPane.add(lblTimettt);
		contentPane.add(lblPacttt);
		contentPane.add(btnBack);
		contentPane.add(btnCancel);
		
		JLabel lblNewLabel_1 = new JLabel("");
		lblNewLabel_1.setIcon(new ImageIcon("images//sea.jpg"));
		lblNewLabel_1.setBounds(0, 0, 613, 326);
		contentPane.add(lblNewLabel_1);
		lblNewLabel.setLayout(null);
	}
	/**
	 * connect with the server
	 * @param e
	 * @throws Exception
	 */
	public void btnConfirmActionPerformed(ActionEvent e) throws Exception {
		
		UserLoginInfo logi=new UserLoginInfo();
		String ip=logi.getIP();
		int port=5555;
		ArrayList<String> msg=new ArrayList<String>();
		
		msg.add("UpdatePrices");
		msg.add(s1);
		msg.add(s2);
		msg.add(s3);
		msg.add(s4);
		msg.add(s5);
		
		
		this.clientCont=new ClientController(ip, port);		
		clientCont.handleMessageFromGui(msg); 
	}

	
}
